/**
 * 项目管理的model
 * @author: zxy
 * @update: 2016-03-15
 */

import {query, save} from '../services/projectManage';
import {message} from 'antd';
import {parse} from 'qs';

export default {

  namespace: 'projectManage',

  state: {
    total: 0,
    pageNumber: 1,
    loading: false,
    pageSize: 10,
    list: [],
    modalVisible: false,
    modalLoading: false,
    modalType: 'create',
    query: {},
    copyNum: 1,
    copyId: null,
    copyModalVisible: false,
  },

  subscriptions: {
    setup({dispatch, history}) {
      history.listen(location => {
        // dispatch({
        //   // type: 'query',
        //   // payload: {
        //   //   pageNumber: 1,
        //   //   pageSize: 10,
        //   // }
        // });
      });
    }
  },

  effects: {
    *query({payload}, {call, put, select}){

    },
    *create({ payload }, { call, put }) {
      yield put({ type: 'showModal' });
    },
    *detail({ payload }, { select, call, put }) {
      yield put({
        type: 'showModal',
        // payload: {
        //   modalType: payload.modalType,
        //   modalLoading: true
        // }
      });
    },
    *'delete'({ payload }, { call, put }) {
      yield put({ type: 'showModal' });
    },
  },

  reducers: {
    querySuccess(state, action) {
      return { ...state, ...action.payload, loading: false, selectedRowKeys: [] };
    },
    updateAction(state, action) {
      return { ...state, ...action.payload };
    },
    showModal(state, action) {
      return { ...state, ...action.payload, modalVisible: true, };
    },
    hideModal(state) {
      return { ...state, modalVisible: false};
    },
  },
};